﻿//
// Copyright (c) 2011 Western Data Solutions (www.westerndatasolutions.com) (Armen Shimoon)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
// the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;

namespace WDS.Bencode.Parsing
{
    /// <summary>
    /// Generic exception thrown when Bencode dictionary encounters a problem during data parsing
    /// </summary>
    public class BencodeParseException : ApplicationException
    {
        /// <summary>
        /// The set of tokens that have been processed so far (if any). Helpful for debugging data encoding problems
        /// </summary>
        public IEnumerable<TokenBase> ProcessedTokens { get; set; }

        /// <summary>
        /// Most general parsing exception with only a message parameter
        /// </summary>
        /// <param name="message">User readable explanation of problem</param>
        public BencodeParseException(string message) : this(message, null) { }

        /// <summary>
        /// Parsing exception that wraps an internal exception with a human readable error message
        /// </summary>
        /// <param name="message">Human readable error message</param>
        /// <param name="failException">Inner exception</param>
        public BencodeParseException(string message, Exception failException) : base(message, failException) { }

        /// <summary>
        /// Parsing exception along with a human readable error message, and the set of tokens that have been processed so far
        /// </summary>
        /// <param name="message">Human readable error message</param>
        /// <param name="failException">The inner exception</param>
        /// <param name="processedTokens">Set of tokens processed before parsing exception</param>
        public BencodeParseException(string message, Exception failException, IEnumerable<TokenBase> processedTokens) :this(message,failException)
        {
            ProcessedTokens = processedTokens;
        }
    }
}
